package com.example.personblog.config;

import com.example.personblog.interceptor.Logininterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
//为了让WebConfig类生效需要加一个注解,@Configuration这个注解会让springboot自动读取WebConfig类这样配置才能生效
@Configuration
public class WebConfig implements WebMvcConfigurer {
    //需要重写增加拦截器的方法\
    @Override
    public void addInterceptors(InterceptorRegistry registry){
        //添加了.addPathPatterns("/user/**");就只拦截user目录下的,不添加则对目前所有请求都做一个拦截
        registry.addInterceptor(new Logininterceptor()).addPathPatterns("/user/**");
    }
}
